package com.yanqu.road.dataHelper.action.zhounianqing;

import com.yanqu.road.dataHelper.action.excel.ZhouNianQingRankData;
import com.yanqu.road.dataHelper.action.excel.ZhouNianRankLogic;
import com.yanqu.road.dataHelper.gameServer.GameServer;
import com.yanqu.road.dataHelper.manager.ServerMgr;
import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.player.UserBeauty;
import com.yanqu.road.entity.servercenter.ServerInfo;
import com.yanqu.road.utils.string.StringUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Callable;

/**
 * 美女亲密度冲榜数据抽取（单服）
 */
public class BeautyDataETLCaller implements Callable<List<ZhouNianQingRankData>> {

    private List<Integer> eventType;

    private int rankType;

    ServerInfo serverInfo;

    int size;

    public BeautyDataETLCaller(List<Integer> eventType, int rankType, ServerInfo serverInfo, int size) {
        this.eventType = eventType;
        this.rankType = rankType;
        this.serverInfo = serverInfo;
        this.size = size;
    }

    @Override
    public List<ZhouNianQingRankData> call() throws Exception {
        GameServer testGameServer = new GameServer(serverInfo);
        ZhouNianRankLogic resource = new ZhouNianRankLogic(testGameServer);
        //List<ZhouNianQingRankData> serverRankList = resource.getServerRankList(serverInfo.getServerId(), eventType, size, rankType);

        List<ZhouNianQingRankData> serverRankList = new ArrayList<>();
        //亲密冲榜
        //本服    1       6
        //跨服    12       2
        Map<Integer, ActivityInfo> activityInfoMap = new ServerMgr().getActivityInfoBy(1, 6, 12, 2, serverInfo.getServerId(), "2021-02-25 00:00:00", "2022-08-15 00:00:00");
        if(activityInfoMap.size() > 0){
            List<Integer> activityIdList = new ArrayList<>();
            for (int id : activityInfoMap.keySet()) {
                activityIdList.add(id);
            }
            serverRankList = resource.getServerRankListByActivityId(serverInfo.getServerId(), activityIdList, size, rankType);
        }

        //填充活动数据
        if(serverRankList.size() > 0) {
            //resource.fillActivityInfo(serverRankList);
            for (ZhouNianQingRankData rankData : serverRankList) {
                if(activityInfoMap.containsKey(rankData.getActivityId())) {
                    rankData.setDataTime(activityInfoMap.get(rankData.getActivityId()).getEndTime());
                }
            }
        }else {
            System.out.println("区服没有亲密冲榜：" + serverInfo.getServerId());
            return serverRankList;
        }

        //填充玩家其他数据-最高美女亲密度
        //美女总亲密|美女id|美女亲密度|美女皮肤|美女品质
        for (ZhouNianQingRankData rankData : serverRankList) {
            List<UserBeauty> userBeautyList = resource.getUserBeauty(rankData.getUserId());
            int beautyId = 0;
            int maxIntimacy = 0;
            int skinId = 0;
            int quality = 0;
            //美女总亲密
            int totalIntimacy = 0;
            for (UserBeauty userBeauty : userBeautyList) {
                totalIntimacy += userBeauty.getTotalIntimacy();
                if(userBeauty.getTotalIntimacy() > maxIntimacy){
                    beautyId = userBeauty.getBeautyId();
                    maxIntimacy = userBeauty.getTotalIntimacy();
                    skinId = userBeauty.getSkinId();
                    quality = userBeauty.getQuality();
                }
            }
            List<String> paramList = new ArrayList<>();
            paramList.add(""+ totalIntimacy);
            paramList.add(""+ beautyId);
            paramList.add(""+ maxIntimacy);
            paramList.add(""+ skinId);
            paramList.add(""+ quality);
            rankData.setOtherValue(StringUtils.listToString(paramList, ZhouNianQingRankData.OTHER_VALUE_SEPARATOR));
        }
        return serverRankList;
    }
}
